package com.saifan.wyy_ov.ui.communitylife;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.common.IconText;
import com.saifan.wyy_ov.ui.onlishop.OnlineShopActivity;
import com.saifan.wyy_ov.ui.property.EngagedServiceActivity;

import java.util.ArrayList;
import java.util.List;

import lomasky.ma.xui.BaseRecyclerViewAdapter;
import lomasky.ma.xui.BaseViewHolder;
import lomasky.ma.xui.RecyclerViewAdapter;


/**
 * @version V1.0.0
 * @author: lomasky
 * @date: 2015-05-05 14:41
 * @descrption 社区生活
 */
public class CommunityLifeFragment extends Fragment {
    RecyclerView recyclerView;
    private View rootView;


    public static CommunityLifeFragment newInstance(int position) {
        CommunityLifeFragment fragment = new CommunityLifeFragment();
        Bundle args = new Bundle();
        args.putInt("position", position);
        fragment.setArguments(args);
        return fragment;
    }

    public List<IconText> models;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,    Bundle savedInstanceState) {
          rootView = inflater.inflate(R.layout.recycler_view, container, false);
        this.recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);

        recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 5));
        models = new ArrayList<>();
        models.add(new IconText(R.mipmap.shoppingmall_online, "在线商城"));
        models.add(new IconText(R.mipmap.convenienttoo, "便民工具"));
        models.add(new IconText(R.mipmap.rentalandsales_information, "租售信息"));
        models.add(new IconText(R.mipmap.fleamarket_big, "跳蚤市场"));
        models.add(new IconText(R.mipmap.forum, "业主论坛"));
        models.add(new IconText(R.mipmap.friends_list_2, "特约服务"));

        RecyclerViewAdapter<IconText> adapter = new RecyclerViewAdapter<IconText>(getContext(), R.layout.home_icon_text) {
            @Override
            public void onBind(BaseViewHolder holder, IconText item, int position) {
                holder.setImage(R.id.icon, item.icon)
                        .setText(R.id.text, item.text);


            }
        };
        adapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(getActivity(), OnlineShopActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(getActivity(), ConvenienttooActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(getActivity(), RentalinfoActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(getActivity(), FleamarketActivity.class));
                        break;
                    case 4:
                        startActivity(new Intent(getActivity(), OwnerBBSActivity.class));
                        break;
                    case 5:
                        startActivity(new Intent(getActivity(), EngagedServiceActivity.class));
                        break;
                    default:
                        break;
                }
            }
        });
        recyclerView.setAdapter(adapter);
        adapter.setData(models);
        adapter.notifyDataSetChanged();
        return rootView;
    }




}
